# frozen_string_literal: true

namespace '/order' do
  helpers ApiHelpers
  before do
    auth_gate
    inject_params
  end

  post '/list' do
    puts @json_params

    objects = Order.valid.only(:order_no, :amt, :user_id, :created_at, :t_id)
    conditions = GlobalHelpers.build_querys(@json_params)
    results = conditions.nil? ? objects : objects.where(conditions)
    paged_result = results.page(@current_page).per(@page_size)
    {
      code: 'ok',
      payload: {
        total: paged_result.count,
        page_size: @page_size,
        objs: paged_result
      }
    }.to_json

    # Member.all.to_json
  end

  post '/delete' do
    puts @json_params
    puts @json_params[:t_id]
    Member.find(@json_params[:t_id]).soft_delete
  end
end
